package com.example.demo.global.config;

import lombok.Data;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 该方法直接从classpath路径下加载文件名为fastdfs-client.properties的配置文件
 * 第二种方法，手动读取配置文件的绝对路径，+ 文件全称，手动加载，见test目录中
 */

//@ConfigurationProperties(prefix = "fastdfs")
@Configuration
@PropertySource("classpath:fastdfs-client.properties")
@Data
public class FastDFSConfig {
    @Value("${connect_timeout_in_seconds}")
    private Integer connect_timeout_in_seconds;
    private Integer network_timeout_in_seconds;
    private String charset;
    private Boolean http_anti_steal_token;
    private String http_secret_key;
    private Integer http_tracker_http_port;
    private List<String> tracker_servers;

    @Bean // 创建的每次都是单利模式
    public FastDFSBean createFastBean(){
        FastDFSBean fastDFSBean = new FastDFSBean();
        fastDFSBean.setTime(this.connect_timeout_in_seconds);
        return fastDFSBean;
    }
    // 创建的不是单利模式
    public FastDFSBean createNoBean(){
        FastDFSBean fastDFSBean = new FastDFSBean();
        fastDFSBean.setTime(this.connect_timeout_in_seconds);
        return fastDFSBean;
    }
}


